/*
 *  Copyright 2008 Danny Lagrouw
 *  
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 *  
 *      http://www.apache.org/licenses/LICENSE-2.0
 *  
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License. 
 */
package org.bastion.example.domain;

import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

import org.bastion.domain.Domain;
import org.bastion.domain.ExampleDomainObject;
import org.bastion.message.QueryMessage;
import org.bastion.query.DomainQuery;

/**
 * @author Danny Lagrouw
 *
 */
public class VehicleType extends ExampleDomainObject {

	private static final long serialVersionUID = 1L;

	private String description;
	
	private Set<Vehicle> vehicles = new HashSet<Vehicle>();
	
	private Amount pricePerDay;

	private VehicleType() {
		super(false);
	}
	
	public VehicleType(String description, Amount pricePerDay) {
		super();
		this.description = description;
		this.pricePerDay = pricePerDay;
	}
	
	public String getDescription() {
		return description;
	}

	public Vehicle addVehicle(String registration, String model) {
		Vehicle vehicle = new Vehicle(registration, model, this);
		vehicles.add(vehicle);
		return vehicle;
	}
	
	public Set<Vehicle> getVehicles() {
		return Collections.unmodifiableSet(vehicles);
	}

	public static List<VehicleType> getVehicleTypes() {
		QueryMessage<VehicleType> queryMessage = new QueryMessage<VehicleType>(new DomainQuery<VehicleType>(VehicleType.class));
		Domain.notify(queryMessage);
		return queryMessage.getResultList();
	}

	public Amount getQuote(Period period) {
		return pricePerDay.multiply(period.getDays());
	}

}
